package com.java.sample;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;

/**
 * Created by lzx on 16/7/23.
 */
@EnableAsync
@SpringBootApplication
public class Application implements CommandLineRunner{

    @Autowired
    AsyncClass asyncClass;

    public static void main(String[] args) {
        SpringApplication.run(Application.class,args);
    }

    @Override
    public void run(String... args) throws Exception {
        System.out.println("start");
//        asyncClass.async();
        async_();
        System.out.println("end");
    }


    /**
     * 同一个类中异步方法不能执行
     * @throws InterruptedException
     */
    @Async
    public void async_() throws InterruptedException {
        Thread.sleep(3000);
        System.out.println("async finished");
    }
}
